<?php

namespace app\common\service\order;
use app\common\model\order\ShopOrderLogModel;

/**
 * 订单日志
 */
class ShopOrderLogService
{

    /**
     * 根据编码添加日志
     * @Author: 易军辉
     * @DateTime:2024-08-29 18:52
     * @param $code 编码
     * @param $info merchant_id:商家ID、shop_order_id:订单ID、data_id:关联ID、order_status：订单状态、remark：备注、create_uid：创建用户
     * @return array
     * @throws \think\Exception
     */
    public static function addByCode($code,$info)
    {
        $model = new ShopOrderLogModel();
        $pk = $model->getPk();
        //订单日志
        $data = array(
            'merchant_id'=>isset($info['merchant_id'])?$info['merchant_id']:null,
            'shop_order_id'=>isset($info['shop_order_id'])?$info['shop_order_id']:null,
            'data_id'=>isset($info['data_id'])?$info['data_id']:null,
            'order_status'=>isset($info['order_status'])?$info['order_status']:null,
            'code'=>$code,
            'title'=>isset($info['title'])?$info['title']:ShopOrderLogModel::getStatus($code,2),
            'remark'=>isset($info['remark'])?$info['remark']:null,
            'create_uid'=>isset($info['create_uid'])?$info['create_uid']:null,
            'create_time'=>date('Y-m-d H:i:s'),
        );
        $model->save($data);
        $id = $model->$pk;
        if (empty($id)) {
            exception();
        }
        $data[$pk] = $id;
        return $data;
    }
}
